//
//  WBRetweetView.swift
//  0829-Weibo
//
//  Created by 毕仲阳 on 16/9/3.
//  Copyright © 2016年 mycompany. All rights reserved.
//

import UIKit

class WBRetweetView: UIView {
    var bottomCons:Constraint?
    var statusViewModel : WBStatusViewModel?
    {
        didSet
        {
            //contentLabel.text = statusViewModel?.status?.retweeted_status?.text
            contentLabel.text = statusViewModel?.retweetStautsText
            //判断转发微博是否有配图
            //更新布局
            self.bottomCons?.uninstall()
            if let pic_urls = statusViewModel?.status?.retweeted_status?.pic_urls,pic_urls.count > 0 {
                pictureView.isHidden = false
                pictureView.pic_urls = pic_urls
                self.snp_updateConstraints(closure: { (make) in
                    self.bottomCons =  make.bottom.equalTo(pictureView).offset(WBStatusCellMargin).constraint
                })
            }else
            {
                pictureView.isHidden = true
                self.snp_updateConstraints(closure: { (make) in
                   self.bottomCons = make.bottom.equalTo(contentLabel).offset(WBStatusCellMargin).constraint
                })
            }
        }
    }
   override init(frame: CGRect) {
        super.init(frame: frame)
        self.setUI()
    }
    
    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    private func setUI()
    {
        self.backgroundColor = UIColor(white: 237/255, alpha: 1)
        //self.backgroundColor = UIColor.yellow
        //添加控件
        self.addSubview(contentLabel)
        self.addSubview(pictureView)
        //布局控件
        contentLabel.snp_makeConstraints { (make)->Void in
            //make.edges.equalTo(self)
            make.top.left.equalTo(self)//.offset(WBStatusCellMargin)
            make.right.equalTo(self).offset(WBStatusCellMargin)
            //make.bottom.equalTo(self).offset(-WBStatusCellMargin)
        }
        //缩略图视图
        pictureView.snp_makeConstraints { (make)->Void in
            //make.width.height.equalTo(100)
            make.top.equalTo(contentLabel.snp_bottom).offset(WBStatusCellMargin)
            make.left.equalTo(contentLabel)
        }
        self.snp_makeConstraints { (make)->Void in
           self.bottomCons =  make.bottom.equalTo(pictureView).offset(WBStatusCellMargin).constraint
        }
        
    }
    private lazy var contentLabel:UILabel = {
       let label = UILabel(textColor: UIColor.darkGray, fontSize: 13)
        label.numberOfLines = 0
        label.preferredMaxLayoutWidth = WBScreenW - 4*WBStatusCellMargin
//        label.text = "ahahaaaaahha"
        return label
    }()
    ///配图
    lazy var pictureView : WBStatusPictureView = {
        let view = WBStatusPictureView(frame: CGRect.zero, collectionViewLayout: UICollectionViewFlowLayout())
        view.backgroundColor = self.backgroundColor
        return view
    }()}
